home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 43
/
Aminet 43 (2001)(GTI - Schatztruhe)[!][Jun 2001].iso
/
Aminet
/
comm
/
tcp
/
rxsocket.lha
/
rxsocket
/
examples
/
udp.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
2001-03-01
|
2KB
|
91 lines
/*
udp test translated into rexx
from Amiga Magazine n.93 udp.c test by Rudi Chiarito
Show the use of udp protocol.
Usage: udp <host> <port> <localPort>
i.e.:
shell1 udp localhost 4000 4001
shell2 udp localhost 4001 4000
to stop push <ctrl-c> in the shells.
To see how rx/tx is stopped just write something in one or both
the shells.
*/
l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
if AddLibrary("rexxsupport.library","rxsocket.library")~=0 then exit
parse arg host remotePort localPort .
if IsDotAddr(host) then do
remote.addrFamily = "INET"
remote.addrAddr = host
end
else do
if ~gethostbyname("H",host) then do
say "udp: host" host "not found."
exit
end
remote.addrFamily = h.hostAddrType
remote.addrAddr = h.hostAddrList.0
end
remote.addrPort = remotePort
sock = socket("INET","DGRAM","IP")
if sock<0 then do
say "udp: can't create socket:" errno()
exit
end
local.addrFamily = "INET"
local.addrAddr = 0
local.addrPort = localPort
if bind(sock,"LOCAL")<0 then do
say "udp: can't bind port:" errno()
exit
end
call IOCtlSocket(sock,"FIONBIO",1)
data = "Ciao"
dataLen = length(data)
down = 0
do while 1
n = SendTo(sock,data,0,"REMOTE")
if n!=dataLen then do
say "udp SendTo() error:" errno()
exit
end
call delay(10)
if down then call WriteCh("STDOUT",".")
n = RecvFrom(sock,"BUFF",10,0,"REMOTE")
if n==-1 then do
err = errno()
if err==35 then do
if ~down then do
call WriteCh("STDOUT","udp: no more data.")
down = 1
end
end
else do
say "udp: RecvFrom() error:" err
exit
end
end
else do
say "udp: read byte(s):" n
down = 0
end
end